What is @fontsource/roboto?
@fontsource/roboto is an npm package that allows you to self-host the Roboto font in your web projects. It provides a convenient way to include the Roboto font family in your application without relying on external CDNs. This package supports various font weights and styles, making it versatile for different design needs.
What are @fontsource/roboto's main functionalities?
Basic Usage
This code imports the default Roboto font into your project. It includes the regular weight and normal style.
import '@fontsource/roboto';
Specific Font Weight
This code imports the Roboto font with a weight of 500. You can specify different weights by changing the number in the import path.
import '@fontsource/roboto/500.css';
Specific Font Style
This code imports the italic style of the Roboto font. You can combine this with different weights as needed.
import '@fontsource/roboto/italic.css';
Advanced Usage with CSS
This code imports the Roboto font with a weight of 500 and italic style. This is useful for more advanced typography needs.
import '@fontsource/roboto/500-italic.css';
Other packages similar to @fontsource/roboto
typeface-roboto
The typeface-roboto package is another option for self-hosting the Roboto font. It offers similar functionality to @fontsource/roboto but is part of the older 'typeface' package series. It may not be as actively maintained as @fontsource/roboto.
fontsource-open-sans
The fontsource-open-sans package allows you to self-host the Open Sans font, which is another popular sans-serif typeface. It offers similar features to @fontsource/roboto, including support for various weights and styles.
fontsource-lato
The fontsource-lato package provides the Lato font family for self-hosting. Like @fontsource/roboto, it supports multiple weights and styles, making it a versatile choice for web typography.
Fontsource Roboto
The CSS and web font files to easily self-host the “Roboto” font. Please visit the main Fontsource website to view more details on this package.
Quick Installation
Fontsource has a variety of methods to import CSS, such as using a bundler like Webpack. Alternatively, it supports SASS. Full documentation can be found here.
yarn add @fontsource/roboto
Within your app entry file or site component, import it in.
import "@fontsource/roboto";
Supported variables:
- Weights:
[100,300,400,500,700,900]
- Styles:
[italic,normal]
- Supported subsets:
[cyrillic,cyrillic-ext,greek,greek-ext,latin,latin-ext,vietnamese]
Finally, you can reference the font name in a CSS stylesheet, CSS Module, or CSS-in-JS.
body {
font-family: "Roboto";
}
Licensing
It is important to always read the license for every font that you use.
Most of the fonts in the collection use the SIL Open Font License, v1.1. Some fonts use the Apache 2 license. The Ubuntu fonts use the Ubuntu Font License v1.0.
Google Fonts License Attributions
Other Notes
Font version (provided by source): v30
.
Feel free to star and contribute new ideas to this repository that aim to improve the performance of font loading, as well as expanding the existing library we already have. Any suggestions or ideas can be voiced via an issue.